#include "Timeout.h"

Timeout::Timeout():_counter(0),_sec(0),_cmp_sec(0)
{
    _cb = nullptr;
    _store_obj.obj = nullptr;
}
Timeout::~Timeout()
{

}
void Timeout::schedule()
{
    if(((++_counter)%4000)==0 && (_sec == (_cmp_sec++))){
        this->update();
        this->cleanup();
    }
}
void Timeout::update()
{
    if(_cb){
        _cb();
    }else if( _store_obj.obj){
        ((_model_function_object::_class*)(_store_obj.obj)->*(_store_obj._methodfunc))();
    }
}
void Timeout::cleanup()
{
    _counter = 0;
    _cmp_sec=0;
}

